<template>
  <component :is="layout"></component>
</template>

<script>
  import loadModule from './common/loadModule'
  import Admin from "./layout/Admin";
  import Empty from './layout/Empty'

  export default {
    name: "App",
    components: {Empty, Admin},
    created() {
      this.loadFrame().then(() => {}).catch(err => {
        console.log(err)
      })
    },
    data(){
      return {
      }
    },
    computed:{
      layout(){
        if(this.$route.meta.hasOwnProperty('layout')){
          return this.$route.meta.layout
        }
        return 'Admin'
      }
    },
    methods: {
      async loadFrame() {
        let moduleList = [
          {
            name: 'user'
          }
        ]
        for (let module of moduleList) {
          loadModule(module.name).then(moduleExport => {
            console.log('加载',moduleExport)
            // 注册路由
            if(moduleExport.hasOwnProperty('routes')){
              this.$router.addRoutes(moduleExport.routes)
            }
            // 注册vuex
            if(moduleExport.hasOwnProperty('store')){
              this.$store.registerModule(module.name, moduleExport.store)
            }
          }).catch(err => {
            console.log('加载失败')
            console.log(err)
          })
        }
      }
    }
  }
</script>

<style scoped>

</style>